package com.sikey.wa04.business.domain.entity;

import com.sikey.wa04.common.enums.LocationType;
import com.sikey.wa04.common.enums.TrajectoryChannel;
import lombok.Data;
import lombok.experimental.Accessors;
import org.gavaghan.geodesy.GlobalCoordinates;

import java.time.Instant;

/**
 * 定位
 *
 * @author luoyangwei
 */
@Data
@Accessors(chain = true)
public class Location {
    /**
     * 地址ID
     */
    private Long id;

    /**
     * 孩子ID
     */
    private ChildId childId;

    /**
     * 定位设备
     */
    private DeviceId deviceId;

    /**
     * 定位类型
     *
     * @see LocationType
     */
    private LocationType type;

    /**
     * 链路ID
     */
    private String traceId;

    /**
     * 渠道
     *
     * @see TrajectoryChannel
     */
    private TrajectoryChannel channel;

    /**
     * 地址数据
     */
    private Address address;

    /**
     * 天气数据
     */
    private Weather weather;

    /**
     * 定位时间
     */
    private Instant positionTime;

    /**
     * 获取坐标
     *
     * @return 坐标
     */
    public GlobalCoordinates getCoordinates() {
        return new GlobalCoordinates(Double.parseDouble(address.getLatitude()), Double.parseDouble(address.getLongitude()));
    }

    /**
     * 设置坐标
     *
     * @param coordinates 坐标
     */
    public void setCoordinates(GlobalCoordinates coordinates) {
        if (address != null) {
            address.setLatitude(String.valueOf(coordinates.getLatitude()));
            address.setLongitude(String.valueOf(coordinates.getLongitude()));
        }
    }
}
