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

use crate::check_total_resource_ratio;
use crate::infrastructure::building::BuildingId;
use crate::infrastructure::building::level::BuildingLevel;
use crate::infrastructure::requirements::InfrastructureRequirements;
use crate::military::unit::stats::prelude::*;
use crate::military::unit::{UnitChunk, UnitChunkSize, UnitId, UnitKind};
use crate::ranking::score::Score;
use crate::resources::prelude::*;
use nil_core_macros::Unit;

#[derive(Unit, Clone, Debug)]
pub struct Archer;

impl Archer {
  pub const ID: UnitId = UnitId::Archer;
  pub const KIND: UnitKind = UnitKind::Ranged;
  pub const BUILDING: BuildingId = BuildingId::Academy;

  pub const SCORE: Score = Score::new(1);

  pub const STATS: UnitStats = UnitStats::builder()
    .attack(AttackPower::new(30))
    .defense(
      DefensePower::builder()
        .cavalry(Power::new(35))
        .infantry(Power::new(40))
        .ranged(Power::new(5))
        .build(),
    )
    .ranged_debuff(RangedDebuff::new(0.5))
    .base_speed(Speed::new(2.0))
    .haul(Haul::new(10))
    .build();

  pub const CHUNK: UnitChunk = UnitChunk {
    size: UnitChunkSize::new(10),
    cost: Cost::new(1_900),
    food_ratio: ResourceRatio::new(0.0),
    iron_ratio: ResourceRatio::new(0.35),
    stone_ratio: ResourceRatio::new(0.15),
    wood_ratio: ResourceRatio::new(0.5),
    maintenance_ratio: MaintenanceRatio::new(0.005),
    workforce: Workforce::new(1),
  };

  pub const INFRASTRUCTURE_REQUIREMENTS: InfrastructureRequirements =
    InfrastructureRequirements::builder()
      .academy(BuildingLevel::new(5))
      .build();
}

check_total_resource_ratio!(
  Archer::CHUNK.food_ratio,
  Archer::CHUNK.iron_ratio,
  Archer::CHUNK.stone_ratio,
  Archer::CHUNK.wood_ratio
);
