package com.salpa.subject.domain.data;


import com.salpa.subject.domain.diff.DiffAble;
import com.salpa.subject.domain.diff.data.DiffType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class TableDocumentResponse {

    private Integer id;

    private Integer databaseDocumentId;

    private String name;

    private String type;

    private String comment;

    private Integer discussionCount;

    private String description;

    @Builder.Default
    private List<ColumnDocumentResponse> columns = new ArrayList<>();

    @Builder.Default
    private List<IndexDocumentResponse> indexes = new ArrayList<>();

    @Builder.Default
    private List<ForeignKeyDocumentResponse> foreignKeys = new ArrayList<>();

    @Builder.Default
    private List<TriggerDocumentResponse> triggers = new ArrayList<>();

    private LocalDateTime createAt;

    private DiffType diffType;

    private TableDocumentResponse original;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class ColumnDocumentResponse implements DiffAble<ColumnDocumentResponse> {
        private Integer id;

        private String name;

        private String type;

        private Integer size;

        private Integer decimalDigits;

        private String comment;

        private String description;

        private Boolean isPrimaryKey;

        private String nullable;

        private String autoIncrement;

        private String defaultValue;

        private LocalDateTime createAt;

        private DiffType diffType;

        private Integer discussionCount;

        private ColumnDocumentResponse original;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class IndexDocumentResponse implements DiffAble<IndexDocumentResponse> {

        private Integer id;

        private String name;

        private Boolean isUnique;

        @Builder.Default
        private List<String> columnNames = new ArrayList<>();

        private String columnNameArray;

        private LocalDateTime createAt;

        private DiffType diffType;

        private IndexDocumentResponse original;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class ForeignKeyDocumentResponse implements DiffAble<ForeignKeyDocumentResponse> {

        private Integer id;

        private String fkName;

        private String fkTableName;

        private String fkColumnName;

        private Integer keySeq;

        private String pkName;

        private String pkTableName;

        private String pkColumnName;

        private String updateRule;

        private String deleteRule;

        private LocalDateTime createAt;

        private DiffType diffType;

        private ForeignKeyDocumentResponse original;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class TriggerDocumentResponse implements DiffAble<TriggerDocumentResponse> {

        private Integer id;

        private String name;

        private String timing;

        private String manipulation;

        private String statement;

        private String triggerCreateAt;

        private LocalDateTime createAt;

        private DiffType diffType;

        private TriggerDocumentResponse original;
    }
}
