import ForgejoKit

enum IssueState: String {
    case open
    case closed
}

enum IssueFilterState: String {
    case open
    case closed
    case all
}

enum PullRequestState: String {
    case open
    case closed
}

enum PullRequestFilterState: String {
    case open
    case closed
    case all
}

enum NotificationSubjectState: String {
    case open
    case closed
    case merged
}

extension Issue {
    var stateValue: IssueState {
        IssueState(rawValue: state) ?? .closed
    }
}

extension Issue {
    var pullRequestStateValue: PullRequestState {
        PullRequestState(rawValue: state) ?? .closed
    }
}

extension PullRequest {
    var stateValue: PullRequestState {
        PullRequestState(rawValue: state) ?? .closed
    }
}

enum InvolvementScope: String, CaseIterable {
    case involved
    case created
    case assigned
    case mentioned
    case reviewRequested = "review_requested"

    static let issueFlags: [InvolvementScope] = [.created, .assigned, .mentioned]
    static let pullRequestFlags: [InvolvementScope] = [.created, .assigned, .mentioned, .reviewRequested]
}

extension NotificationSubject {
    var stateValue: NotificationSubjectState? {
        guard let state else { return nil }
        return NotificationSubjectState(rawValue: state)
    }
}
