package com.kingtom.shengtai.api.model;

import java.util.List;
import java.util.Map;

import com.kingtom.shengtai.api.mapper.SrmMapper;
import com.kingtom.shengtai.app.srm.model.SrmSupplierDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 应用模块名称</p>
 * 代码描述</p>
 * Copyright: Copyright (C) 2023 , Inc. All rights reserved. <p>
 * Company: 成都诚唐科技有限责任公司</p>
 *
 * @author wany
 * @since 2023/12/21
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "供应商信息")
public class SrmSupplierDTO{

    @Schema(description = "id")
    private String id;

    @Schema(description = "名称")
    private String name;

    @Schema(description = "联系人")
    private String person;

    @Schema(description = "联系电话")
    private String phone;

    @Schema(description = "联系地址")
    private String address;

    @Schema(description = "供应商类型")
    private String type;

    @Schema(description = "评分")
    private String mark;

    @Schema(description = "备注")
    private String remark;

    @Schema(description = "图片集合")
    private List<String> image;

    @Schema(description = "产品集合")
    private List<String> product;

    @Schema(description = "供应商状态")
    private Integer state;

    @Schema(description = "扩展字段1")
    private String ext1;

    @Schema(description = "扩展字段2")
    private String ext2;

    @Schema(description = "扩展字段3")
    private Map<String, Object> ext3;

    @Schema(description = "创建时间")
    private String gmtCreate;

    @Schema(description = "更新时间")
    private String gmtModified;

    @Schema(description = "系统ID")
    private String sysId;

    @Schema(description = "企业简介")
    private String intro;

    @Schema(description = "企业营业执照")
    private String businessLicense;

    @Schema(description = "国家权威认证机构颁发的证书")
    private List<String> certificates;

    @Schema(description = "联系人姓名")
    private String personName;

    /**
     * 兼容移动端修改供应商信息接口。
     */
    @Schema(description = "图片集合字符串，多个用逗号隔开")
    private String imageStr;

    /**
     * 兼容移动端修改供应商信息接口。
     */
    @Schema(description = "国家权威认证机构颁发的证书字符串，多个用逗号隔开")
    private String certificatesStr;

    @Schema(description = "优势产品")
    private String superiorProduct;


    public static SrmSupplierDTO convert(SrmSupplierDO supplierDO){
        if(supplierDO == null || supplierDO.getSupplier() == null){
            return null;
        }
        SrmSupplierDTO convert = SrmMapper.INSTANCE.convert(supplierDO.getSupplier());
        if(convert == null){
            return null;
        }
        convert.setPersonName(supplierDO.getUser() == null ? null : supplierDO.getUser().getName());
        return convert;
    }

}
