using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

[SerializeField]
public class Attacker {
  [SerializeField] public int BaseDamage { get; protected set; } = 0;

  public void StartAttackPreparation() => AttackReadyAt = Time.time + AttackPreparationTime;
  public bool AttackIsReady => AttackPreparationTimeLeft == 0;
  public float AttackReadyAt { get; protected set; }
  [SerializeField] public float AttackPreparationTime { get; protected set; } = 0;
  public float AttackPreparationTimeLeft => Math.Max(0, AttackReadyAt - Time.time);
  public float AttackPreparationTimeLeftNormalized => Math.Max(0, (AttackReadyAt - Time.time) / AttackPreparationTime);
  public float AttackPreparationTimeElapsed => AttackPreparationTime - AttackPreparationTimeLeft;
  public float AttackPreparationTimeElapsedNormalized => 1 - AttackPreparationTimeLeftNormalized;

  public void StartAttackCooldown() => AttackCooldown = Time.time + AttackCooldownDuration;
  public bool CanAttack => Time.time > AttackCooldown;
  public float AttackCooldown { get; protected set; }
  public float AttackCooldownLeft => Math.Max(0, AttackCooldown - Time.time);
  [SerializeField] public float AttackCooldownDuration { get; protected set; } = 1f;
}


public interface IAttacker {
  public int BaseDamage { get;} 

  public void StartAttackPreparation() ;
  public float AttackReadyAt { get;  }
  public float AttackPreparationTime { get; } 
  public float AttackPreparationTimeLeft { get; }
  public float AttackPreparationTimeLeftNormalized { get; }
  public float AttackPreparationTimeElapsed { get; }
  public float AttackPreparationTimeElapsedNormalized { get; }
  public bool AttackIsReady => AttackPreparationTimeLeft == 0;

  public void StartAttackCooldown() ;
  public bool CanAttack => Time.time > AttackCooldown;
  public float AttackCooldown { get; }
  public float AttackCooldownLeft { get; }
  public float AttackCooldownDuration { get; }
}

