use chrono::{Duration, Local, NaiveDateTime};

#[derive(Debug)]
struct AIState {
    relation_score: f32,
    previous_score: f32,
    decay_rate: f32,
    sensitivity: f32,
    message_threshold: f32,
    last_message_time: NaiveDateTime,
}

impl AIState {
    fn update(&mut self, now: NaiveDateTime) {
        let days_passed = (now - self.last_message_time).num_days() as f32;
        let decay = self.decay_rate * days_passed;
        self.previous_score = self.relation_score;
        self.relation_score -= decay;
        self.relation_score = self.relation_score.clamp(0.0, 100.0);
    }

    fn should_talk(&self) -> bool {
        let delta = self.previous_score - self.relation_score;
        delta > self.message_threshold && self.sensitivity > 0.5
    }

    fn generate_message(&self) -> String {
        let _delta = self.previous_score - self.relation_score;
        match self.relation_score as i32 {
            80..=100 => "ふふっ、最近どうしてる？会いたくなっちゃった！".to_string(),
            60..=79 => "ちょっとだけ、さみしかったんだよ？".to_string(),
            40..=59 => "えっと……話せる時間ある？".to_string(),
            _ => "ううん、もしかして私のこと、忘れちゃったのかな……".to_string(),
        }
    }
}

fn main() {
    let now = Local::now().naive_local();
    let mut ai = AIState {
        relation_score: 80.0,
        previous_score: 80.0,
        decay_rate: 1.5,            // 1日あたりの減少スコア
        sensitivity: 0.8,
        message_threshold: 5.0,
        last_message_time: now - Duration::days(4), // 最後の会話から4日経過
    };

    ai.update(now);

    if ai.should_talk() {
        println!("AI発話: {}", ai.generate_message());
    } else {
        println!("まだ何も言わずにそっとしているようです...");
    }
}
