# -*- coding: utf-8 -*-
from odoo import api, fields, models


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

    mycompany_engagement_reminders = fields.Boolean(
        string='Engagement Reminders',
        config_parameter='my_company.engagement_reminders',
        help='Send weekly reminders to users who have not posted on My Company.',
    )
    mycompany_default_startup = fields.Boolean(
        string='Default Startup for New Users',
        config_parameter='my_company.default_startup',
        help='Automatically set My Company as the home action for new internal users.',
    )
    mycompany_hub_name = fields.Char(
        string='Hub Display Name',
        config_parameter='my_company.hub_name',
        default='My Company',
        help='Name shown on the hub and in the app menu (e.g. Silicon Overdrive).',
    )

    def set_values(self):
        super().set_values()
        hub_name = (self.mycompany_hub_name or 'My Company').strip() or 'My Company'
        menu = self.env.ref('my_company.menu_my_company_root', raise_if_not_found=False)
        action = self.env.ref('my_company.action_my_company_hub', raise_if_not_found=False)
        if menu:
            menu.sudo().write({'name': hub_name})
        if action:
            action.sudo().write({'name': hub_name})
        if self.mycompany_default_startup:
            action = self.env.ref('my_company.action_my_company_hub')
            users = self.env['res.users'].sudo().search([
                ('share', '=', False),
                ('active', '=', True),
                ('action_id', '=', False),
            ])
            users.write({'action_id': action.id, 'mycompany_startup': True})
