from django_filters import rest_framework as filters
from apps.wpm.models import SfLog, StLog, WMaterial, Mlog, Handover
['mgroup', 'shift', 'team', 'leader', 'team__belong_dept']


class SfLogFilter(filters.FilterSet):
    class Meta:
        model = SfLog
        fields = {
            "mgroup": ["exact"],
            "shift": ["exact"],
            "team": ["exact"],
            "leader": ["exact"],
            "team__belong_dept": ["exact"],
            "end_time": ["day", "month", "year", "lt"],
            "start_time": ["gte"]
        }


class StLogFilter(filters.FilterSet):
    class Meta:
        model = StLog
        fields = {
            "mgroup": ["exact"],
            "mgroup__name": ["exact"],
            "start_time": ["day", "month", "year"],
            "end_time": ["isnull"],
            "sflog": ["exact"],
            "sflogs": ["exact"]
        }


class WMaterialFilter(filters.FilterSet):
    class Meta:
        model = WMaterial
        fields = {
            "material": ["exact", "in"],
            "material__type": ["exact", "in"],
            "material__process": ["exact", "in"],
            "belong_dept": ["exact"],
            "belong_dept__name": ["exact", "in"],
            "batch": ["exact"],
            "count": ["gte", "lte", "exact"]
        }


class MlogFilter(filters.FilterSet):
    class Meta:
        model = Mlog
        fields = {
            "mtask": ["exact", "in"],
            "batch": ["exact"],
            "handle_date": ["exact"],
            "handle_user": ["exact"],
            "mgroup": ["exact"],
            "mtask__mgroup__belong_dept__name": ["exact", "contains", "in"],
            "mgroup__belong_dept__name": ["exact", "in", "contains"],
            "mgroup__name": ["exact", "in", "contains"],
            "submit_time": ["isnull"]
        }


class HandoverFilter(filters.FilterSet):

    class Meta:
        model = Handover
        fields = {
            "send_user": ["exact"],
            "send_dept": ["exact"],
            "send_dept__name": ["exact"],
            "recive_dept": ["exact"],
            "recive_dept__name": ["exact"],
            "send_date": ["exact"],
            "material__type": ["exact", "in"],
            "submit_time": ["isnull"],
            "mlog": ["isnull"],
            "send_mgroup": ["exact"]
        }
