package com.yueqian.xingyun.sc.bo.stock.take.plan;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lframework.starter.common.constants.StringPool;
import com.lframework.starter.web.core.bo.BaseBo;
import com.lframework.starter.web.core.utils.ApplicationUtil;
import com.yueqian.xingyun.basedata.entity.StoreCenter;
import com.yueqian.xingyun.basedata.service.storecenter.StoreCenterService;
import com.yueqian.xingyun.sc.entity.TakeStockPlan;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import lombok.Data;

@Data
public class TakeStockPlanSelectorBo extends BaseBo<TakeStockPlan> {

    /**
     * ID
     */
    @Schema(description = "ID")
    private String id;

    /**
     * 业务单据号
     */
    @Schema(description = "业务单据号")
    private String code;

    /**
     * 仓库编号
     */
    @Schema(description = "仓库编号")
    private String scCode;

    /**
     * 仓库名称
     */
    @Schema(description = "仓库名称")
    private String scName;

    /**
     * 盘点类别
     */
    @Schema(description = "盘点类别")
    private Integer takeType;

    /**
     * 盘点状态
     */
    @Schema(description = "盘点状态")
    private Integer takeStatus;

    /**
     * 创建时间
     */
    @Schema(description = "创建时间")
    @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
    private LocalDateTime createTime;

    /**
     * 修改时间
     */
    @Schema(description = "修改时间")
    @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
    private LocalDateTime updateTime;

    public TakeStockPlanSelectorBo(TakeStockPlan dto) {

        super(dto);
    }

    @Override
    public <A> BaseBo<TakeStockPlan> convert(TakeStockPlan dto) {

        return super.convert(dto, TakeStockPlanSelectorBo::getTakeType, TakeStockPlanSelectorBo::getTakeStatus);
    }

    @Override
    protected void afterInit(TakeStockPlan dto) {

        this.takeType = dto.getTakeType().getCode();
        this.takeStatus = dto.getTakeStatus().getCode();

        StoreCenterService storeCenterService = ApplicationUtil.getBean(StoreCenterService.class);
        StoreCenter sc = storeCenterService.findById(dto.getScId());
        this.scCode = sc.getCode();
        this.scName = sc.getName();
    }
}
