package com.ruoyi.database.util;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.database.domain.PassVehicleInfo;
import com.ruoyi.database.domain.ReleaseRequestInfo;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 简单JSON转换工具
 */
@Component
public class SimpleJsonConverter {

    /**
     * 将JSON转换为PassVehicleInfo
     */
    public PassVehicleInfo toPassVehicleInfo(JSONObject json) {
        if (json == null) return null;

        PassVehicleInfo info = new PassVehicleInfo();

        // 直接赋值
        info.setDirect(json.getInteger("direct"));
        info.setPlateNo(json.getString("plateNo"));
        info.setParkCode(json.getString("parkCode"));
        info.setGateCode(json.getString("gateCode"));
        info.setLaneNo(json.getString("laneNo"));
        info.setInUnid(json.getString("inUnid"));
        info.setOutUnid(json.getString("outUnid"));
        info.setInTime(json.getString("inTime"));
        info.setOutTime(json.getString("outTime"));

        return info;
    }

    /**
     * 将JSON转换为ReleaseRequestInfo
     */
    public ReleaseRequestInfo toReleaseRequestInfo(JSONObject json) {
        if (json == null) return null;

        ReleaseRequestInfo info = new ReleaseRequestInfo();

        // 直接赋值
        info.setDirect(json.getInteger("direct"));
        info.setPlateNo(json.getString("plateNo"));
        info.setPassTime(json.getString("passTime"));
        info.setParkCode(json.getString("parkCode"));
        info.setGateCode(json.getString("gateCode"));
        info.setLaneNo(json.getString("laneNo"));
        info.setInUnid(json.getString("inUnid"));
        info.setOutUnid(json.getString("outUnid"));
        info.setParkType(json.getInteger("parkType"));
        info.setPlateType(json.getInteger("plateType"));
        info.setPlateColor(json.getInteger("plateColor"));
        info.setCarType(json.getInteger("carType"));

        return info;
    }
}
