/*
 * Copyright (c) 2025, LJason. All Rights Reserved.
 */

use serde::{Deserialize, Serialize};

/// 账号凭据
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct Account {
    sessdata: Option<String>,
    bili_jct: Option<String>,
}

impl Account {
    pub fn set_sessdata(&mut self, sessdata: impl Into<String>) {
        self.sessdata = Some(sessdata.into());
    }

    pub fn set_bili_jct(&mut self, bili_jct: impl Into<String>) {
        self.bili_jct = Some(bili_jct.into());
    }

    /// 获取 Cookie 字符串
    #[must_use]
    pub fn to_cookie_str(&self) -> String {
        let mut cookies = Vec::new();

        if let Some(sessdata) = &self.sessdata {
            cookies.push(format!("SESSDATA={sessdata}"));
        }

        if let Some(bili_jct) = &self.bili_jct {
            cookies.push(format!("bili_jct={bili_jct}"));
        }

        cookies.join("; ")
    }
}
