package com.qqchen.deploy.backend.deploy.integration.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;

/**
 * Git分支响应对象
 */
@Data
public class GitBranchResponse {

    private String name;

    @JsonProperty("default")
    private Boolean isDefaultBranch;

    @JsonProperty("can_push")
    private Boolean canPush;

    @JsonProperty("developers_can_push")
    private Boolean developersCanPush;

    @JsonProperty("developers_can_merge")
    private Boolean developersCanMerge;

    @JsonProperty("commit")
    private GitCommitResponse commit;

    @JsonProperty("web_url")
    private String webUrl;

    @Data
    public static class GitCommitResponse {
        private String id;
        private String message;
        private String author_name;
        
        @JsonProperty("authored_date")
        private OffsetDateTime authoredDate;
        
        @JsonProperty("committed_date")
        private OffsetDateTime committedDate;
    }

    public String getCommitId() {
        return commit != null ? commit.id : null;
    }

    public String getCommitMessage() {
        return commit != null ? commit.message : null;
    }

    public String getCommitAuthor() {
        return commit != null ? commit.author_name : null;
    }

    public LocalDateTime getCommitDate() {
        return commit != null && commit.authoredDate != null ? 
            commit.authoredDate.atZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime() : null;
    }

    public LocalDateTime getLastUpdateTime() {
        return commit != null && commit.committedDate != null ? 
            commit.committedDate.atZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime() : null;
    }

    public LocalDateTime getLastCommitTime() {
        return getLastUpdateTime();
    }
}