package com.yiqi.core.domain.vo.wx;

import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import me.chanjar.weixin.common.util.json.GsonParser;

import java.util.List;

/**
 * 门店同城配送信息
 * @author xiaohei
 * @date 2024/1/31
 */
@Data
public class IntracityExpressStoreInfoResult extends IntracityExpressBaseResult{

    @JsonProperty("store_list")
    @ApiModelProperty("门店信息列表")
    private List<StoreInfo> store_list;

    @ApiModelProperty("符合条件的门店总数")
    private int total;

    @Data
    public static class StoreInfo{
        @JsonProperty("wx_store_id")
        @ApiModelProperty("微信门店编号")
        private String wx_store_id;

        @JsonProperty("out_store_id")
        @ApiModelProperty("自定义门店编号")
        private String out_store_id;

        @JsonProperty("city_id")
        @ApiModelProperty("门店所在城市ID")
        private String city_id;

        @JsonProperty("order_pattern")
        @ApiModelProperty("运力偏好（1：价格优先，2：运力优先）默认价格优先")
        private String order_pattern;

        @JsonProperty("service_trans_prefer")
        @ApiModelProperty("优先使用的运力ID,order_pattern = 2时必填")
        private String service_trans_prefer;

        @JsonProperty("address_info")
        @ApiModelProperty("门店地址信息")
        private AddressInfo address_info;
    }

    @Data
    public static class AddressInfo{
        @ApiModelProperty("省/自治区/直辖市")
        private String province;

        @ApiModelProperty("地级市")
        private String city;

        @ApiModelProperty("县/县级市/区")
        private String area;

        @ApiModelProperty("街道")
        private String street;

        @ApiModelProperty("具体门牌号或详细地址")
        private String house;

        @ApiModelProperty("门店所在地纬度")
        private Double lat;

        @ApiModelProperty("门店所在地经度")
        private Double lng;

        @ApiModelProperty("门店联系电话")
        private String phone;
    }

    public static List<IntracityExpressStoreInfoResult> fromJsonList(String json) {
        JsonObject jsonObject = GsonParser.parse(json);
        return WxMaGsonBuilder.create().fromJson(jsonObject.get("list").toString(), (new TypeToken<List<IntracityExpressStoreInfoResult>>() {
        }).getType());
    }

    public static IntracityExpressStoreInfoResult fromJson(String json) {
        return WxMaGsonBuilder.create().fromJson(json, IntracityExpressStoreInfoResult.class);
    }

}
