module Teams
  class StaffCoverage
    def initialize(team)
      @team = team
    end

    def assigned_count(_kind = "transmission")
      members_count + pending_invitations_count
    end

    def covered_count(_kind = "transmission")
      assigned_count.positive? ? 1 : 0
    end

    def role_label_for(membership)
      return "Trasmissione" if membership.staff_kind.present?

      nil
    end

    def open_slot_for_invite?(_kind = "transmission")
      assigned_count < 1
    end

    private

    def members_count
      @team.user_teams.where.not(staff_kind: nil).count
    end

    def pending_invitations_count
      @team.team_invitations.pending.count
    end
  end
end
