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

#[derive(Clone, Debug)]
pub struct TCleanBmpFlashOptions {
  pub index: i32,
}

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

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

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

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

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

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