/* © SRSoftware 2025 */
package de.srsoftware.umbrella.user.model;


import static de.srsoftware.tools.Strings.base64;
import static de.srsoftware.umbrella.core.constants.Field.NAME;
import static de.srsoftware.umbrella.core.constants.Field.URL;
import static de.srsoftware.umbrella.user.Constants.*;
import static java.nio.charset.StandardCharsets.UTF_8;

import de.srsoftware.tools.Mappable;
import java.util.HashMap;
import java.util.Map;

public record LoginService(String name, String url, String clientId, String clientSecret, String userInfoField) implements Mappable {

	@Override
	public Map<String,Object> toMap() {
		var map = new HashMap<String,Object>();
		map.put(NAME,name);
		map.put(URL,url);
		map.put(CLIENT_ID,clientId);
		map.put(CLIENT_SECRET,clientSecret);
		map.put(USER_INFO_FIELD,userInfoField);
		return map;
	}

	public String basicAuth() {
		return "Basic "+base64((clientId+":"+clientSecret).getBytes(UTF_8));
	}
}
