# Copyright (c) 2014 Rackspace Hosting.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from django.utils.translation import ugettext_lazy as _

from horizon import tables

from solumdashboard.api.client import client as solumclient


class CreateAssembly(tables.LinkAction):
    name = "create"
    verbose_name = _("New Assembly")
    url = "horizon:solum:assemblies:create"
    classes = ("btn-launch", "ajax-modal")


class DeleteAssembly(tables.BatchAction):
    name = "delete"
    verbose_name = _("Delete Assembly")
    classes = ("btn-terminate", "btn-danger")

    action_present = _("Delete")
    action_past = _("Deleted")
    data_type_singular = _("Assembly")
    data_type_plural = _("Assemblies")

    def allowed(self, request, template):
        return True

    def action(self, request, assembly_id):
        solum = solumclient(request)
        solum.assemblies.delete(assembly_id=assembly_id)


class ViewAssembly(tables.LinkAction):
    name = "view"
    verbose_name = _("View")
    url = "horizon:solum:assemblies:detail"
    classes = ("btn-edit",)


class AssembliesTable(tables.DataTable):
    uuid = tables.Column('uuid', verbose_name=_('UUID'),
                         link=("horizon:solum:assemblies:detail"))
    name = tables.Column('name', verbose_name=_('Name'))
    application = tables.Column('application', verbose_name=_('Application'),
                                link=("horizon:solum:applications:detail"))
    description = tables.Column('description', verbose_name=_('Description'))

    def get_object_id(self, app):
        return app.uuid

    class Meta(object):
        name = "assemblies"
        verbose_name = _("Assemblies")
        table_actions = (DeleteAssembly,)
        row_actions = (ViewAssembly, DeleteAssembly)

@@ -636,16 +636,68 @@
 azy as _
+%0Afrom django.utils.translation import ungettext_lazy
 %0A%0Afrom h
@@ -999,13 +999,14 @@
 les.
-Batch
+Delete
 Acti
@@ -1014,207 +1014,297 @@
 n):%0A
+%0A
     
-name = %22delete%22%0A    verbose_name = _(%22Delete Assembly%22)%0A    classes = (%22btn-terminate%22, %22btn-danger%22)%0A%0A    action_present = _(%22Delete%22)%0A    action_past = _(%22Deleted%22)%0A    data_type_singular = _(%22
+@staticmethod%0A    def action_present(count):%0A        return ungettext_lazy(%0A            u%22Delete Assembly%22,%0A            u%22Delete Assemblies%22,%0A            count%0A        )%0A%0A    @staticmethod%0A    def action_past(count):%0A        return ungettext_lazy(%0A            u%22Scheduled deletion of 
 Asse
@@ -1312,47 +1312,85 @@
 bly%22
-)
+,
 %0A    
-data_type_plural = _(%22Assemblies%22
+        u%22Scheduled deletion of Assemblies%22,%0A            count%0A        
 )%0A%0A 

Refactor the DeleteAssembly action