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

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
    _inherit = 'res.config.settings'

    fpv_default_preview_print = fields.Boolean(
        string='Default Preview Print',
        config_parameter='fusion_pdf_preview.default_preview_print',
        default=True,
        help='Default value for PDF preview when new users are created.',
    )

    fpv_default_automatic_printing = fields.Boolean(
        string='Default Automatic Printing',
        config_parameter='fusion_pdf_preview.default_automatic_printing',
        help='Default value for automatic printing when new users are created.',
    )

    def action_fpv_apply_to_all_users(self):
        """Apply current default PDF preview settings to all internal users in the company."""
        self.ensure_one()
        users = self.env['res.users'].search([
            ('share', '=', False),
            ('company_id', '=', self.env.company.id),
        ])
        users.write({
            'preview_print': self.fpv_default_preview_print,
            'automatic_printing': self.fpv_default_automatic_printing,
        })
        return {
            'type': 'ir.actions.client',
            'tag': 'display_notification',
            'params': {
                'title': 'PDF Preview Settings',
                'message': f'Settings applied to {len(users)} user(s).',
                'type': 'success',
                'sticky': False,
            }
        }
