The basis must fit the purpose. Data collected to perform a contract with a customer is processed on the contract basis for that purpose. If the company later wants to use the same data for something else, such as licensing it for AI training, it has to ask which basis supports the new use. The original one does not carry over automatically.
For new commercial uses the candidates are usually consent and legitimate interests. Consent must be freely given, specific and informed, and it can be withdrawn. It is hard to obtain after the fact and is treated with caution in employment. Legitimate interests requires a three-part assessment: a real interest, necessity of the processing, and a balance against the rights and reasonable expectations of the people concerned. Special categories of data need an additional condition. The simplest route is often to anonymize, because truly anonymous data is not personal data and needs no basis. United States privacy laws do not use the lawful basis concept in the same way. This is general information, not legal advice.
The assessment should be written down and dated. Regulators can ask a controller to show how it chose its basis.