from url_filter.filtersets import ModelFilterSet
from django_filters import rest_framework as filters

from django.contrib.auth.models import User

from LiveStock.models import Cooperative
from authentication.models import UserProfile, SystemUserProfile
from panel.models import (CityOperatorCheckRequest, PoultryRequestExchange, Poultry, ProvinceOperator,
                          KillHouse, Vet, KillHouseOperator, CityOperator, KillHouseDriver, InspectorOperator,
                          PoultryHatching, Guilds, KillHouseRequest, ProvinceKillRequest, PoultryRequest, KillRequest,
                          WagePayment, ChainAllocation, InternalTransaction, ChainCompany, KillHouseFreeBarInformation,
                          OutProvincePoultryRequestBuyer, ReportsUsers, Dispenser, StewardAllocation,
                          OutProvinceCarcassesBuyer, KillHouseFreeSaleBarInformation, BaseOutProvinceCarcassesBuyer,
                          ColdHouseAllocations, ColdHouse, SubSectorTransactions, StewardFreeBarInformation,
                          PosSegmentation, PosMachineTransactions, BarDifferenceRequest, POSDeviceSession,
                          HatchingIncreaseRequest, CommonlyUsed, StewardFreeSaleBarInformation, DirectBuyingPayment,
                          PoultryScience, PoultryScienceReport, WarehouseArchive, POSMachine, EvacuationHatchingDetail,
                          DispenserInformation, Representative)
from authentication.models import City

# test
from ticket.models import TicketSupport


class CityOperatorRequestFilterSet(ModelFilterSet):
    class Meta:
        model = CityOperatorCheckRequest


class CityOperatorFilterSet(ModelFilterSet):
    class Meta:
        model = CityOperator


class PoultryRequestExchangeFilterSet(ModelFilterSet):
    class Meta:
        model = PoultryRequestExchange


class PoultryRequestFilterSet(ModelFilterSet):
    class Meta:
        model = PoultryRequest


class OutProvincePoultryRequestBuyerFilterSet(ModelFilterSet):
    class Meta:
        model = OutProvincePoultryRequestBuyer


class PoultryFilterSet(ModelFilterSet):
    class Meta:
        model = Poultry


class ChainCompanyFilterSet(ModelFilterSet):
    class Meta:
        model = ChainCompany


class ChainAllocationFilterSet(ModelFilterSet):
    class Meta:
        model = ChainAllocation


class InternalTransactionFilterSet(ModelFilterSet):
    class Meta:
        model = InternalTransaction


class DispenserAllocationFilterSet(ModelFilterSet):
    class Meta:
        model = StewardAllocation


class StewardAllocationFilterSet(ModelFilterSet):
    class Meta:
        model = StewardAllocation


class StewardAllocationDashboardFilterSet(filters.FilterSet):
    class Meta:
        model = StewardAllocation
        fields = [
            'guilds__user__first_name',
            'guilds__user__last_name',
            'guilds__user__fullname',
            'guilds__user__mobile',
            'steward__user__first_name',
            'steward__user__last_name',
            'steward__user__fullname',
            'steward__user__mobile',
            'kill_house__kill_house_operator__user__first_name',
            'kill_house__kill_house_operator__user__last_name',
            'kill_house__kill_house_operator__user__fullname',
            'kill_house__kill_house_operator__user__mobile',
            'kill_house__name',
            'to_guilds__user__first_name',
            'to_guilds__user__last_name',
            'to_guilds__user__fullname',
            'to_guilds__user__mobile',
            'to_steward__user__first_name',
            'to_steward__user__last_name',
            'to_steward__user__fullname',
            'to_steward__user__mobile',
            'to_kill_house__kill_house_operator__user__first_name',
            'to_kill_house__kill_house_operator__user__last_name',
            'to_kill_house__kill_house_operator__user__fullname',
            'to_kill_house__kill_house_operator__user__mobile',
            'to_kill_house__name',
        ]


class StewardFreeBarInformationFilterSet(ModelFilterSet):
    class Meta:
        model = StewardFreeBarInformation


class StewardFreeSaleBarInformationFilterSet(ModelFilterSet):
    class Meta:
        model = StewardFreeSaleBarInformation
        fields = [
            'steward__user__fullname',
            'steward__user__first_name',
            'steward__user__last_name',
            'steward__user__mobile',
            'buyer__user__fullname',
            'buyer__user__first_name',
            'buyer__user__last_name',
            'buyer__user__mobile',
            'province',
            'city',
            'province'
            'buyer_name'
            'buyer_mobile'

        ]


class PosSegmentationFilterSet(ModelFilterSet):
    class Meta:
        model = PosSegmentation


class PosMachineTransactionsFilterSet(ModelFilterSet):
    class Meta:
        model = PosMachineTransactions


class POSMachineFilterSet(ModelFilterSet):
    class Meta:
        model = POSMachine


class ColdHouseFilterSet(ModelFilterSet):
    class Meta:
        model = ColdHouse


class ColdHouseAllocationsFilterSet(ModelFilterSet):
    class Meta:
        model = ColdHouseAllocations


class DispenserFilterSet(ModelFilterSet):
    class Meta:
        model = Dispenser


class RepresentativeFilterSet(ModelFilterSet):
    class Meta:
        model = Representative


class DispenserInformationFilterSet(ModelFilterSet):
    class Meta:
        model = DispenserInformation


class ReportsUsersFilterSet(ModelFilterSet):
    class Meta:
        model = ReportsUsers


class CooperativeFilterSet(ModelFilterSet):
    class Meta:
        model = Cooperative
        fields = [
            'user__fullname',
            'user__mobile',
            'name',
            'mobile',
        ]


class GuildsFilterSet(filters.FilterSet):
    kill_house = filters.ModelMultipleChoiceFilter(
        queryset=KillHouse.objects.all(),
        field_name='kill_house',
        to_field_name='id'
    )

    # stewards = filters.ModelMultipleChoiceFilter(
    #     queryset=Guilds.objects.all(),
    #     field_name='stewards',
    #     to_field_name='id'
    # )

    class Meta:
        model = Guilds
        fields = [
            'user__mobile',
            'user__first_name',
            'user__last_name',
            'user__fullname',
            'user__city__name',
            'user__national_code',
            'user__national_id',
            'user__province__name',
            'address__city__name',
            'guilds_name',
            'type_activity',
            'area_activity',
            'guilds_id',
            'license_number',
            'kill_house__name',
            'stewards__user__mobile',
            'stewards__user__first_name',
            'stewards__user__last_name',
        ]


class TestGuildsFilterSet(filters.FilterSet):
    kill_house = filters.ModelMultipleChoiceFilter(
        queryset=KillHouse.objects.all(),
        field_name='kill_house',
        to_field_name='id'
    )

    class Meta:
        model = Guilds
        fields = [
            'user__mobile',
            'user__first_name',
            'user__last_name',
            'user__city__name',
            'user__province__name',
            'address__city__name',
            'guilds_name',
            'type_activity',
            'area_activity',
            'kill_house__name',
        ]


class ProvinceKillRequestFilterSet(ModelFilterSet):
    class Meta:
        model = ProvinceKillRequest


class UserProfileFilterSet(ModelFilterSet):
    class Meta:
        model = UserProfile


class ProvinceOperatorFilterSet(ModelFilterSet):
    class Meta:
        model = ProvinceOperator


class InspectorOperatorFilterSet(ModelFilterSet):
    class Meta:
        model = InspectorOperator


class KillHouseFilterSet(ModelFilterSet):
    class Meta:
        model = KillHouse


class KillHouseFreeSaleBarInformationFilterSet(ModelFilterSet):
    class Meta:
        model = KillHouseFreeSaleBarInformation


class DirectBuyingPaymentFilterSet(ModelFilterSet):
    class Meta:
        model = DirectBuyingPayment


class KillHouseOperatorFilterSet(ModelFilterSet):
    class Meta:
        model = KillHouseOperator


class KillHouseDriverFilterSet(ModelFilterSet):
    class Meta:
        model = KillHouseDriver


class VetFilterSet(ModelFilterSet):
    class Meta:
        model = Vet


class KillHouseFreeBarInformationFilterSet(ModelFilterSet):
    class Meta:
        model = KillHouseFreeBarInformation


class PoultryHatchingFilterSet(ModelFilterSet):
    class Meta:
        model = PoultryHatching
        fields = [
            'poultry__user__first_name',
            'poultry__user__last_name',
            'poultry__user__fullname',
            'poultry__user__mobile',
            'poultry__unit_name',
            'poultry__address__city__name',
            'chicken_age',
            'licence_number',
            'poultry__breeding_unique_id',
            'CertId',
            'PersonTypeName',
            'InteractTypeName',
            'UnionTypeName',
            'poultry__city_operator',

        ]


class EvacuationHatchingDetailFilterSet(ModelFilterSet):
    class Meta:
        model = EvacuationHatchingDetail


class KillHouseRequestFilterSet(ModelFilterSet):
    class Meta:
        model = KillHouseRequest


class BarDifferenceRequestFilterSet(ModelFilterSet):
    class Meta:
        model = BarDifferenceRequest


class KillRequestFilterSet(ModelFilterSet):
    class Meta:
        model = KillRequest


class WagePaymentFilterSet(ModelFilterSet):
    class Meta:
        model = WagePayment


class DashboardEnterLoadInformationFilterSet(filters.FilterSet):
    class Meta:
        model = KillHouseRequest
        fields = [
            'killhouse_user__kill_house_operator__user__fullname',
            'killhouse_user__kill_house_operator__user__mobile',
            'province_request__poultry_request__poultry__user__fullname',
            'province_request__poultry_request__poultry__user__mobile',
            'province_request__poultry_request__order_code',
            'province_request__poultry_request__order_code',
            'bar_code',
        ]


class DashboardPoultryRequestFilterSet(filters.FilterSet):
    class Meta:
        model = PoultryRequest
        fields = [
            'order_code',
            'poultry__user__mobile',
            'poultry__user__fullname',
            'poultry__user__first_name',
            'poultry__user__last_name',
            'poultry__address__city__name',

        ]


class DashboardKillHouseFreeBarInformationFilterSet(filters.FilterSet):
    class Meta:
        model = KillHouseFreeBarInformation
        fields = [
            'kill_house__name',
            'poultry_name',
            'poultry_mobile',
            'province',
            'city',
            'driver_name',
            'driver_mobile',
            'bar_clearance_code',
            'kill_house__kill_house_operator__user__mobile',
            'kill_house__kill_house_operator__user__fullname',

        ]


class VetFarmAndKillHouseFilterSet(ModelFilterSet):
    class Meta:
        model = Vet
        fields = [
            'user__national_id',
            'user__base_order',
            'user__mobile',
            'user__fullname'

        ]


class ProvinceKillRequestNewFilterSet(filters.FilterSet):
    class Meta:
        model = ProvinceKillRequest
        fields = [
            'province_request__poultry_request__order_code',
            'killhouse_user__name',
            'killhouse_user__kill_house_operator__user__fullname',
            'killhouse_user__kill_house_operator__user__mobile',
            'killhouse_user__kill_house_operator__address__city__name',
            'province_request__poultry_request__poultry__unit_name',
            'province_request__poultry_request__poultry__user__fullname',
            'province_request__poultry_request__poultry__user__mobile',
            'province_request__poultry_request__poultry__address__city__name',
        ]


class ReturnProvinceKillRequestFilterSet(ModelFilterSet):
    class Meta:
        model = ProvinceKillRequest


class PoultryManageFilterSet(filters.FilterSet):
    class Meta:
        model = Poultry
        fields = [
            'breeding_unique_id',
            'user__national_id',
            'user__base_order',
            'user__mobile',
            'user__first_name',
            'user__last_name',
            'address__city__name',
            'unit_name',

        ]


class DashboardKillRequestFilterSet(filters.FilterSet):
    class Meta:
        model = KillRequest
        fields = [
            'kill_house__kill_house_operator__user__fullname',
            'kill_house__kill_house_operator__user__first_name',
            'kill_house__kill_house_operator__user__last_name',
            'kill_house__kill_house_operator__user__mobile',
            'kill_house__name',
            'slaughter_house__name',
            'export_country',
            'export_code',
            'direct_buying_code',
            'poultry__user__fullname',
            'poultry__user__mobile',
            'poultry__unit_name',

        ]


# class TicketsFilterSet(filters.FilterSet):
#     to_user = filters.ModelMultipleChoiceFilter(
#         queryset=SystemUserProfile.objects.all(),
#         field_name='to_user',
#         to_field_name='id'
#     )
#
#     class Meta:
#         model = TicketSupport
#         fields = [
#             'user__fullname',
#             'user__mobile',
#             'title',
#             'ticket_id',
#             'to_user__fullname',
#             'to_user__mobile',
#
#         ]


class BaseOutProvinceCarcassesBuyerFilterSet(ModelFilterSet):
    class Meta:
        model = BaseOutProvinceCarcassesBuyer


class OutProvinceCarcassesBuyerFilterSet(ModelFilterSet):
    class Meta:
        model = OutProvinceCarcassesBuyer


class SubSectorTransactionsFilterSet(ModelFilterSet):
    class Meta:
        model = SubSectorTransactions


class CommonlyUsedFilterSet(ModelFilterSet):
    class Meta:
        model = CommonlyUsed


class TicketsFilterSet(filters.FilterSet):
    class Meta:
        model = TicketSupport
        fields = [
            'ticket_id',
            'user__fullname',
            'title',

        ]


class GuildsForPostationFilterSet(ModelFilterSet):
    class Meta:
        model = Guilds
        fields = [
            'user__first_name',
            'user__last_name',
            'user__fullname',
            'user__mobile',
            'guilds_name'
        ]


class GuildsForArchiveFilterSet(ModelFilterSet):
    class Meta:
        model = Guilds
        fields = [
            'user__first_name',
            'user__last_name',
            'user__fullname',
            'user__mobile',
            'guilds_name'
        ]


class GuildsForGeneralConfigsFilterSet(ModelFilterSet):
    class Meta:
        model = Guilds

        fields = [
            'user__mobile',
            'user__first_name',
            'user__last_name',
            'user__city__name',
            'user__province__name',
            'address__city__name',
            'guilds_name',
            'type_activity',
            'area_activity',
        ]


class POSDeviceSessionForCompanyFilterSet(ModelFilterSet):
    class Meta:
        model = POSDeviceSession
        fields = [
            'pos__terminal_number',
            'pos__pos_id',
            'pos__pos_company__name',
            'pos__guild__guilds_name',
            'pos__guild__user__fullname',
            'pos__guild__user__national_code',

        ]


class WarehouseArchiveFilterSet(ModelFilterSet):
    class Meta:
        model = WarehouseArchive
        fields = [
            'kill_house__kill_house_operator__user__fullname'
            'kill_house__kill_house_operator__user__mobile'
            'steward__user__fullname'
            'steward__user__mobile'
            'guild__user__fullname'
            'guild__user__mobile'

        ]


class HatchingIncreaseRequestFilterSet(ModelFilterSet):
    class Meta:
        model = HatchingIncreaseRequest
        fields = [
            'hatching__poultry__unit_name',
            'hatching__poultry__user__fullname',
            'hatching__poultry__user__mobile',
            'hatching__poultry__breeding_unique_id',
            'hatching__licence_number',
            'registerer_name',
            'registerer_mobile',
        ]


class PoultryRequestDirectBuyingFilterSet(ModelFilterSet):
    class Meta:
        model = PoultryRequest
        fields = [
            'poultry__unit_name',
            'poultry__user__fullname',
            'poultry__user__mobile',
            'poultry__breeding_unique_id',
            'hatching__licence_number'
        ]


class PoultryScienceFilterSet(ModelFilterSet):
    class Meta:
        model = PoultryScience
        fields = [
            'poultry__unit_name',
            'poultry__user__fullname',
            'poultry__user__mobile',
            'poultry__breeding_unique_id',
            'user__mobile',
            'user__first_name',
            'user__last_name',
            'user__fullname',
        ]


class PoultryScienceReportFilterSet(ModelFilterSet):
    class Meta:
        model = PoultryScienceReport
        fields = [
            'hatching__poultry__unit_name',
            'hatching__poultry__user__fullname',
            'hatching__poultry__user__mobile',
            'hatching__poultry__breeding_unique_id',
            'hatching__licence_number',
            'poultry_science__user__mobile',
            'poultry_science__user__first_name',
            'poultry_science__user__last_name',
            'poultry_science__user__fullname',
        ]
