import collections
import functools
import json

import marshmallow_jsonapi
from marshmallow_jsonapi import fields

from flask_jsonapi import api
from flask_jsonapi import decorators
from flask_jsonapi import resource_repository_views

JSONAPI_HEADERS = {'content-type': 'application/vnd.api+json', 'accept': 'application/vnd.api+json'}


class ExampleSchema(marshmallow_jsonapi.Schema):
    id = fields.UUID(required=True)
    body = fields.Str()

    class Meta:
        type_ = 'example'
        self_view_many = 'example_list'
        self_view = 'example_detail'
        self_view_kwargs = {'example_id': '<id>'}
        strict = True


ExampleModel = collections.namedtuple('ExampleModel', 'id body')


class Repository:
    def __init__(self):
        self.deleted_ids = []

    def create(self, data, **kwargs):
        return ExampleModel(**data)

    def get_list(self, filters=None, pagination=None):
        return [
            ExampleModel(id='f60717a3-7dc2-4f1a-bdf4-f2804c3127a4', body='heheh'),
            ExampleModel(id='f60717a3-7dc2-4f1a-bdf4-f2804c3127a5', body='hihi'),
        ]

    def get_detail(self, id):
        return ExampleModel(id=id, body='Gwynbelidd')

    def delete(self, id):
        self.deleted_ids.append(id)

    def update(self, id, **data):
        pass


class ExampleResourceRepositoryViewSet(resource_repository_views.ResourceRepositoryViewSet):