Documentation
use std::sync::{Arc, Mutex};

use psdk_father::{
  args::{ArgContext, PsdkArgBase, PsdkEasyArg},
  command::{CommandClause, PsdkTextCommand},
  errors::PsdkFatherResult,
};

#[derive(Clone, Debug)]
pub struct CWaterMarkOptions {
  /// 水印类型 (0就正常 打印没水印)
  pub mark_type: u32,
  /// 水印浓度值(0-255)
  pub value: i32,
}

#[derive(Clone, Debug)]
pub struct CWaterMark {
  options: CWaterMarkOptions,
  ctx: Arc<Mutex<ArgContext>>,
}

impl CWaterMark {
  pub fn new(options: CWaterMarkOptions) -> Self {
    Self {
      options,
      ctx: Default::default(),
    }
  }
}

impl From<i32> for CWaterMark {
  fn from(value: i32) -> Self {
    Self::new(CWaterMarkOptions {
      mark_type: 0,
      value,
    })
  }
}

impl PsdkEasyArg<String> for CWaterMark {
  fn context(&self) -> Arc<Mutex<ArgContext>> {
    self.ctx.clone()
  }
}

impl PsdkArgBase<String> for CWaterMark {
  fn header(&self) -> String {
    "WAT".to_string()
  }

  fn clause(&self) -> PsdkFatherResult<CommandClause> {
    let mut ptc = PsdkTextCommand::with_header_format_cpcl(self.header());
    ptc.append(self.options.value);
    Ok(ptc.clause())
  }
}

psdk_father::impl_psdk_arg_to_easy_arg!(String, CWaterMark, true);