package com.jeequan.jeepay.db.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jeequan.jeepay.core.model.BaseModel;
import com.jeequan.jeepay.core.model.ip.IpAddressResult;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;

/**
 * <p>
 * ip关联地区缓存表
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2024-03-21
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_ip_location")
@NoArgsConstructor
public class IpLocation extends BaseModel {

    private static final long serialVersionUID=1L;

    /**
     * ip
     */
    @TableId(type = IdType.INPUT)
    private String ip;

    /**
     * 省份名称
     */
    private String provinceName;

    /**
     * 省份编码
     */
    private String provinceCode;

    /**
     * 城市名称
     */
    private String cityName;

    /**
     * 城市编码
     */
    private String cityCode;

    /**
     * 地区名称
     */
    private String areaName;

    /**
     * 区域编码
     */
    private String areaCode;

    /**
     * 地址
     */
    private String address;

    /**
     * 备注
     */
    private String remark;

    /**
     * 创建时间
     */
    private Date createdAt;

    @TableField(exist = false)
    private Byte state;

    public IpLocation(IpAddressResult addressResult) {
        this.ip = addressResult.getIp();
        this.provinceName = addressResult.getPro();
        this.provinceCode = addressResult.getProCode();
        this.cityName = addressResult.getCity();
        this.cityCode = addressResult.getCityCode();
        this.areaName = addressResult.getRegion();
        this.areaCode = addressResult.getRegionCode();
        this.address = addressResult.getAddr();
        this.remark = addressResult.getErr();
        this.state = addressResult.getState();
    }
}
