// Copyright (C) Call of Nil contributors
// SPDX-License-Identifier: AGPL-3.0-only

use crate::check_total_resource_ratio;
use crate::infrastructure::building::{BuildingId, BuildingLevel, StorageId};
use crate::infrastructure::requirements::InfrastructureRequirements;
use crate::infrastructure::storage::StorageCapacity;
use crate::ranking::score::Score;
use crate::resources::cost::{Cost, ResourceRatio};
use crate::resources::maintenance::MaintenanceRatio;
use crate::resources::workforce::Workforce;
use nil_core_macros::{Building, Storage};
use serde::{Deserialize, Serialize};

#[derive(Building, Storage, Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
pub struct Warehouse {
  level: BuildingLevel,
  enabled: bool,
}

impl Warehouse {
  pub const ID: BuildingId = BuildingId::Warehouse;
  pub const STORAGE_ID: StorageId = StorageId::Warehouse;

  pub const MIN_LEVEL: BuildingLevel = BuildingLevel::ZERO;
  pub const MAX_LEVEL: BuildingLevel = BuildingLevel::new(30);

  pub const MIN_COST: Cost = Cost::new(500);
  pub const MAX_COST: Cost = Cost::new(100_000);

  pub const FOOD_RATIO: ResourceRatio = ResourceRatio::new(0.0);
  pub const IRON_RATIO: ResourceRatio = ResourceRatio::new(0.2);
  pub const STONE_RATIO: ResourceRatio = ResourceRatio::new(0.4);
  pub const WOOD_RATIO: ResourceRatio = ResourceRatio::new(0.4);

  pub const MAINTENANCE_RATIO: MaintenanceRatio = MaintenanceRatio::new(0.005);

  pub const MIN_WORKFORCE: Workforce = Workforce::new(2);
  pub const MAX_WORKFORCE: Workforce = Workforce::new(250);

  pub const MIN_CAPACITY: StorageCapacity = StorageCapacity::new(2_500);
  pub const MAX_CAPACITY: StorageCapacity = StorageCapacity::new(400_000);

  pub const MIN_SCORE: Score = Score::new(6);
  pub const MAX_SCORE: Score = Score::new(1_187);

  pub const INFRASTRUCTURE_REQUIREMENTS: InfrastructureRequirements =
    InfrastructureRequirements::none();
}

impl const Default for Warehouse {
  fn default() -> Self {
    Self {
      level: BuildingLevel::new(1),
      enabled: true,
    }
  }
}

check_total_resource_ratio!(
  Warehouse::FOOD_RATIO,
  Warehouse::IRON_RATIO,
  Warehouse::STONE_RATIO,
  Warehouse::WOOD_RATIO
);
