# w.c.s. - web application for online forms
# Copyright (C) 2005-2020  Entr'ouvert
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

from wcs.qommon import N_
from quixote import get_publisher

from wcs.workflows import register_item_class
from wcs.carddef import CardDef

from wcs.wf.create_formdata import (CreateFormdataWorkflowStatusItem,
                                    LinkedFormdataEvolutionPart)


class LinkedCardDataEvolutionPart(LinkedFormdataEvolutionPart):
    formdef_class = CardDef


class CreateCarddataWorkflowStatusItem(CreateFormdataWorkflowStatusItem):
    description = N_('Create Card Data')
    key = 'create_carddata'
    category = 'formdata-action'
    ok_in_global_action = True

    formdef_class = CardDef
    evolution_part_class = LinkedCardDataEvolutionPart

    formdef_label = N_('Card')
    mappings_label = N_('Mappings to new card fields')
    varname_hint = N_('This is used to get linked card in expressions.')

    @classmethod
    def is_available(cls, workflow=None):
        return get_publisher().has_site_option('studio')

    def get_parameters(self):
        return ('formdef_slug', 'mappings', 'keep_user', 'varname', 'condition')


register_item_class(CreateCarddataWorkflowStatusItem)
