package com.its.op.dto.its.vds;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.PositiveOrZero;
import java.io.Serializable;

/**
 * VDS 제어기 제어정보 DTO Class
 */
@Data
@Builder
@ApiModel("VdsControlDto(VDS 제어 정보")
public class VdsControlDto implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModel("VdsControlResetReq(VDS 제어기 리셋)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class VdsControlResetReq {

        @ApiModelProperty("로그인 사용자 ID")
        @JsonProperty("user_id")
        private String userId;

        @Builder
        public VdsControlResetReq(String user_id) {
            this.userId = user_id;
        }
    }

    @ApiModel("VdsControlRes(VDS 제어기 제어 응답)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class VdsControlRes {

        @ApiModelProperty("제어결과(0: 성공, 기타: 오류")
        @JsonProperty("error")
        private Integer error;

        @ApiModelProperty("제어결과메시지")
        @JsonProperty("message")
        private String message;

        @ApiModelProperty("정지영상이미지")
        @JsonProperty("image")
        private String image;

        public void setImage(String image) {
            this.image = image;
        }
        public void setResult(Integer error, String message) {
            this.error = error;
            this.message = message;
        }
        @Builder
        public VdsControlRes(Integer error, String message) {
            this.error = error;
            this.message = message;
            this.image = null;
        }
    }

    @ApiModel("VdsControlStopImageReq(VDS 영상정보 요청)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class VdsControlStopImageReq {

        @ApiModelProperty("카메라번호(기본:1)")
        @JsonProperty("camera_no")
        @PositiveOrZero
        private Integer cameraNo;

        @ApiModelProperty("프레임번호(무조건:0)")
        @JsonProperty("frame_no")
        @PositiveOrZero
        private Integer frameNo;

        @ApiModelProperty("로그인 사용자 ID")
        @JsonProperty("user_id")
        private String userId;

        @Builder
        public VdsControlStopImageReq(Integer camera_no, String user_id) {
            this.cameraNo = camera_no;
            this.userId = user_id;
        }
    }

    @ApiModel("VdsControlStopImageRes(VDS 영상정보 요청 응답)")
    @Getter
    @Setter
    @ToString
    @NoArgsConstructor//(access = AccessLevel.PROTECTED)
    public static class VdsControlStopImageRes {

        @ApiModelProperty("제어결과(0: 성공, 기타: 오류")
        @JsonProperty("error")
        private Integer error;

        @ApiModelProperty("제어결과메시지")
        @JsonProperty("message")
        private String message;

        @ApiModelProperty("영상이미지")
        @JsonProperty("image")
        private byte[] image;

        public void setResult(Integer error, String message) {
            this.error = error;
            this.message = message;
        }
        @Builder
        public VdsControlStopImageRes(Integer error, String message, byte[] image) {
            this.error = error;
            this.message = message;

            // FOR KISA Secure Coding pass
            //this.image = image;
            this.image = null;
            if (image != null && image.length > 0) {
                this.image = new byte[image.length];
                System.arraycopy(image, 0, this.image, 0, image.length);
            }
        }
    }
}
