# -*- coding: utf-8 -*-

from django.contrib import admin
from django_admin import ReadOnlyModelAdmin, Readonly2ModelAdmin

from logs.models import MchInfoDecryptLogInfo, MchInfoEncryptLogInfo, MchLogInfo, RedpackSendLogInfo


class MchInfoEncryptLogInfoAdmin(Readonly2ModelAdmin, admin.ModelAdmin):
    list_display = ('plaintext', 'alg', 'ciphertext', 'brand_pk', 'model_pk', 'distributor_pk', 'sn', 'application_id', 'code', 'code_url', 'operator_id', 'is_send_redpack', 'redpack_amount', 'redpack_max_amount', 'has_send_redpack', 'redpack_send_amount', 'user_id', 'nickname', 'is_clerk_send_redpack', 'clerk_redpack_amount', 'clerk_redpack_max_amount', 'has_clerk_send_redpack', 'clerk_redpack_send_amount', 'clerk_user_id', 'clerk_nickname', 'status', 'created_at', 'updated_at')
    list_filter = ('alg', 'brand_pk', 'model_pk', 'distributor_pk', 'operator_id', 'is_send_redpack', 'has_send_redpack', 'is_clerk_send_redpack', 'has_clerk_send_redpack', 'status')
    readonly_fields_exclude = ('is_send_redpack', 'redpack_amount', 'redpack_max_amount', 'is_clerk_send_redpack', 'clerk_redpack_amount', 'clerk_redpack_max_amount')

    fieldsets = (
        (u'基本信息', {
            'fields': ('plaintext', 'alg', 'ciphertext', 'brand_pk', 'model_pk', 'distributor_pk', 'sn', 'operator_id', 'status', 'created_at', 'updated_at')
        }),
        (u'一物一码', {
            'classes': ('collapse', ),
            'fields': ('application_id', 'code', 'code_url')
        }),
        (u'消费者红包信息', {
            'classes': ('collapse', ),
            'fields': ('is_send_redpack', 'redpack_amount', 'redpack_max_amount', 'has_send_redpack', 'redpack_send_amount', 'user_id', 'nickname')
        }),
        (u'销售员红包信息', {
            'classes': ('collapse', ),
            'fields': ('is_clerk_send_redpack', 'clerk_redpack_amount', 'clerk_redpack_max_amount', 'has_clerk_send_redpack', 'clerk_redpack_send_amount', 'clerk_user_id', 'clerk_nickname')
        }),
    )


class MchInfoDecryptLogInfoAdmin(ReadOnlyModelAdmin, admin.ModelAdmin):
    list_display = ('ciphertext', 'brand_pk', 'model_pk', 'distributor_pk', 'sn', 'application_id', 'code', 'code_url', 'decrypt_count', 'status', 'created_at', 'updated_at')
    list_filter = ('brand_pk', 'model_pk', 'distributor_pk', 'status')


class MchLogInfoAdmin(ReadOnlyModelAdmin, admin.ModelAdmin):
    list_display = ('log_id', 'log_file', 'operator_id', 'app_version', 'status', 'created_at', 'updated_at')
    list_filter = ('operator_id', 'app_version', 'status')
    search_fields = ('operator_id', 'app_version')


class RedpackSendLogInfoAdmin(ReadOnlyModelAdmin, admin.ModelAdmin):
    list_display = ('brand_id', 'user_id', 'nickname', 'phone', 'sn', 'redpack_type', 'redpack_amount', 'is_clerk_redpack', 'status', 'created_at', 'updated_at')
    list_filter = ('redpack_type', 'is_clerk_redpack', 'status')


admin.site.register(MchInfoDecryptLogInfo, MchInfoDecryptLogInfoAdmin)
admin.site.register(MchInfoEncryptLogInfo, MchInfoEncryptLogInfoAdmin)
admin.site.register(MchLogInfo, MchLogInfoAdmin)
admin.site.register(RedpackSendLogInfo, RedpackSendLogInfoAdmin)
