from django_filters import rest_framework as filters
from apps.ofm.models import MroomBooking, BorrowRecord, VehicleUse

from .models import LendingSeal
from apps.utils.filters import MyJsonListFilter

class MroomBookingFilterset(filters.FilterSet):
    class Meta:
        model = MroomBooking
        fields = {
            'slot_b__mroom': ['exact', 'in'],
            'slot_b__booking': ['exact'],
            'slot_b__mdate': ['exact', 'gte', 'lte'],
            'create_by': ['exact'],
            "id": ["exact"]
        }

class VehicleFilterset(filters.FilterSet):
    class Meta:
        model = VehicleUse
        fields = {
            'slot_vehicle__vehreg': ['exact', 'in'],
            'slot_vehicle__vdate': ['exact', 'gte', 'lte'],
            'create_by': ['exact'],
            "id": ["exact"]
        }


class SealFilter(filters.FilterSet):
    seal = MyJsonListFilter(label='按印章名称查询', field_name="seal")

    class Meta:
        model = LendingSeal
        fields = ['seal']


class BorrowRecordFilter(filters.FilterSet):
    file_name = filters.CharFilter(label='按文件名称查询', field_name="borrow_file__name", lookup_expr='icontains')
    borrow_user = filters.CharFilter(label='按借阅人查询', field_name="create_by__name", lookup_expr='icontains')
    class Meta:
        model = BorrowRecord
        fields = ['file_name', 'borrow_user']