class ReportSchema(BaseSchema):
    url = URLFor('.report_detail', id='<id>', _external=True)
    sample = ForeignReferenceField(endpoint='.sample_detail', queryset=Sample.objects(), query_parameter='id')
    analysis_system = ForeignReferenceField(endpoint='.analysis_system_detail', queryset=AnalysisSystem.objects(), query_parameter='identifier_name')
    json_report_objects = FileMapField(endpoint='.json_report_object', file_url_key='object_name')
    raw_report_objects = FileMapField(endpoint='.raw_report_object', file_url_key='object_name')

    class Meta(BaseSchema.Meta):
        model = Report
        dump_only = [
            'id',
            '_cls',
            'upload_date',
            'status'
        ]

    @pre_dump
    def _clean_analysis_date(self, data):
        if data.analysis_date:
            data.analysis_date = data.analysis_date.replace(microsecond=0)
        return data class SampleSchema(BaseSchema):
    url = URLFor('.sample_detail', id='<id>', _external=True)
    dispatched_to = List(ForeignReferenceField(endpoint='.analysis_system_detail', queryset=AnalysisSystem.objects(), query_parameter='identifier_name'))

    class Meta(BaseSchema.Meta):
        model = Sample
        exclude = ['created_by', 'comments']
        dump_only = [
            'id',
            'dispatched_to',
            '_cls',
            'delivery_date'
        ] class FileSampleSchema(SampleSchema):
    file = URLFor('.sample_download', id='<id>', _external=True)

    class Meta(BaseSchema.Meta):
        model = FileSample
        exclude = ['created_by', 'comments']
        dump_only = SampleSchema.Meta.dump_only + [
            'file_size',
            'file_names',
            'magic_string',
            'md5sum',
            'sha1sum',
            'sha256sum',
            'sha512sum',
            'shannon_entropy',
            'ssdeep_hash'
        ] class ExecutableBinarySampleSchema(FileSampleSchema):
    class Meta(BaseSchema.Meta):
        model = ExecutableBinarySample
        exclude = ['created_by', 'comments']
        dump_only = FileSampleSchema.Meta.dump_only + [
            'filesystem_events',
            'registry_events',
            'sections',
            'resources',
            'imports',
            'strings'
        ] class IPSampleSchema(SampleSchema):
    class Meta(BaseSchema.Meta):
        model = IPSample
        exclude = ['created_by', 'comments']
        dump_only = SampleSchema.Meta.dump_only class DomainSampleSchema(SampleSchema):
    class Meta(BaseSchema.Meta):
        model = DomainSample
        exclude = ['created_by', 'comments']
        dump_only = SampleSchema.Meta.dump_only class URISampleSchema(SampleSchema):
    class Meta(BaseSchema.Meta):
        model = URISample
        exclude = ['created_by', 'comments']
        dump_only = SampleSchema.Meta.dump_only class SampleRelationSchema(BaseSchema):
    url = URLFor('.sample_relation_detail', id='<id>', _external=True)
    sample = ForeignReferenceField(endpoint='.sample_detail', queryset=Sample.objects(), query_parameter='id')
    other = ForeignReferenceField(endpoint='.sample_detail', queryset=Sample.objects(), query_parameter='id')

    class Meta(BaseSchema.Meta):
        model = SampleRelation
        dump_only = [
                'id',
                '_cls'
                ] class DroppedBySampleRelationSchema(SampleRelationSchema):
    class Meta(BaseSchema.Meta):
        model = DroppedBySampleRelation
        dump_only = SampleRelationSchema.Meta.dump_only class ResolvedBySampleRelationSchema(SampleRelationSchema):
    class Meta(BaseSchema.Meta):
        model = ResolvedBySampleRelation
        dump_only = SampleRelationSchema.Meta.dump_only class ContactedBySampleRelationSchema(SampleRelationSchema):
    class Meta(BaseSchema.Meta):
        model = ContactedBySampleRelation
        dump_only = SampleRelationSchema.Meta.dump_only class RetrievedBySampleRelationSchema(SampleRelationSchema):
    class Meta(BaseSchema.Meta):
        model = RetrievedBySampleRelation
        dump_only = SampleRelationSchema.Meta.dump_only class SsdeepSampleRelationSchema(SampleRelationSchema):
    match = Float()

    class Meta(BaseSchema.Meta):
        model = SsdeepSampleRelation
        dump_only = SampleRelationSchema.Meta.dump_only
from mass_flask_api.schemas import SampleSchema, FileSampleSchema, ExecutableBinarySampleSchema, ReportSchema, IPSampleSchema, DomainSampleSchema, URISampleSchema
from mass_flask_api.schemas import SampleRelationSchema, DroppedBySampleRelationSchema, ResolvedBySampleRelationSchema, ContactedBySampleRelationSchema, RetrievedBySampleRelationSchema, SsdeepSampleRelationSchema


class SchemaMapping:
    @staticmethod
    def get_schema_for_model_class(model_class_name):
        model_conversion = {
                'Sample': SampleSchema,
                'FileSample': FileSampleSchema,
                'ExecutableBinarySample': ExecutableBinarySampleSchema,
                'IPSample': IPSampleSchema,
                'DomainSample': DomainSampleSchema,
                'URISample': URISampleSchema,
                'SampleRelation': SampleRelationSchema,

                'DroppedBySampleRelation': DroppedBySampleRelationSchema,