package com.ycwl.basic.model;

import com.ycwl.basic.model.pc.printer.resp.MemberPrintResp;
import com.ycwl.basic.utils.JacksonUtil;
import lombok.Data;

/**
 * 打印订单项(用于管线处理)
 */
@Data
public class PrinterOrderItem {

    private Long id;
    private Long sourceId;
    private String cropUrl;
    private Crop crop;

    /**
     * 从MemberPrintResp转换
     */
    public static PrinterOrderItem fromMemberPrintResp(MemberPrintResp resp) {
        PrinterOrderItem item = new PrinterOrderItem();
        item.setId(resp.getId() != null ? resp.getId().longValue() : null);
        item.setSourceId(resp.getSourceId());
        item.setCropUrl(resp.getCropUrl());

        if (resp.getCrop() != null) {
            try {
                Crop crop = new Crop();
                Integer rotation = JacksonUtil.getInt(resp.getCrop(), "rotation");
                if (rotation != null) {
                    crop.setRotation(rotation);
                }
                item.setCrop(crop);
            } catch (Exception e) {
                // 解析失败,crop为null
            }
        }

        return item;
    }
}
